package com.xzy.shop.web.servlet;

import com.xzy.shop.domain.Category;
import com.xzy.shop.service.CategoryService;
import com.xzy.shop.service.impl.CategoryServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/category/*")
public class CategoryServlet extends BaseServlet {
    CategoryService servlet = new CategoryServiceImpl();

    public void findAll(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        List<Category> list = servlet.findAll();
        writeValue(list, response);
    }

    public void findCategoryByGid(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String gid = request.getParameter("gid");
        Category category = servlet.findCategory(gid);
        writeValue(category, response);
    }

    public void findNameByCid(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String cid = request.getParameter("cid");
        String name = servlet.findNameByCid(cid);
        writeValue(name, response);
    }
}
